<template>
  <div class="commodity-property">
    <div class="commodity-header">
      <span class="left_icon fa fa-2x fa-angle-left returnUpper" @click="goBack"></span>
      <div class="commodity-item">
        <a class="commodity" href="#merchandise">商品</a>
        <a class="details" href="#particulars">详情</a>
      </div>
      <span class="share"><img src="../../assets/tubiao/share.png" height="12" width="12"/></span>
    </div>
    <div class="productsIn" id="merchandise" >
      <div class="commodity-picture">
        <van-swipe @change="onChange">
          <van-swipe-item v-for="(Info, key) in fsInfos.prodImage" :key="key">
            <img class="pictureImg" :src="Info" />
          </van-swipe-item>
          <div class="custom-indicator" slot="indicator">
            {{ current + 1 }}/{{fsInfos.prodImage.length}}
          </div>
        </van-swipe>
      </div>
      <div class="commodity-introduce">
        <p class="commodity-title">{{fsInfos.prodSupTitle}}</p>
        <span class="commodity-hint">该商品追高可以使用30元优惠券</span>
        <p class="commodity-price">￥{{fsInfos.currentPrice}}</p>
      </div>
      <div class="commodity-safeguard">
        <img src="../../assets/tubiao/salableProduct.png"/>
        <p class="safeguard-title"> 100%正平保障</p>
      </div>
      <div class="shoppingAddress">
        <span class="dispatching">派送至</span>
        <span class="dispatch-location">{{addressArr}}</span>
        <span class="left_icon fa fa-2x fa-angle-right autonSelect"></span>
        <div class="available">有货</div>
      </div>
      <div class="SelectNumber">
        <span>已选</span>
        <span class="commodity-number">{{index}}件</span>
        <span class="left_icon fa fa-2x fa-angle-right autonSelect"></span>
      </div>
    </div>
    <div class="productDetails">
      <div class="CommodTitle" id="particulars">
        <div></div>
        <p>商品详情</p>
      </div>
      <div class="imgDisplay">
        <ul>
          <li v-for="(item, key) in fsInfos.prodImage" :key="key">
            <img :src="item"  class="detailsPic"/>
          </li>
        </ul>
      </div>
    </div>

    <div class="trolleyCarMask" v-show="isShow" @click="reselectPro"  catchtouchmove="preventD"></div>
    <div class="selectArea" v-show="isShow"  catchtouchmove="preventD">
      <div class="merchandNews">
        <div class="pictureArea">
          <img :src="fsInfos.prodImage[0]"/>
        </div>
        <p class="Locaedprice">￥{{fsInfos.currentPrice}}</p>
        <p class="productID">商品编号:{{fsInfos._id}}</p>
      </div>
      <div class="selectNub">
        <span>数量</span>
        <div class="selectNubBtn">
          <div class="reduce" @click="reduceNub">-</div>
          <div class="itesNumber">
            <input type="text" v-model="index"/>
            </div>
          <div class="augment" @click="augmentNub">+</div>
        </div>
      </div>
      <div class="affirmBtn" @click="confirm">确认</div>
  </div>

    <div class="commodity-footer">
      <i class="iconfont icon-cart_icon shoppingCart" @click="shoppingTrolley"></i>
      <div class="commodityBtn">
        <div class="addToCart" @click="addToCart">加入购物车</div>
        <div class="immediatelyBuy">立即购买</div>
      </div>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'commodity-property',
    data() {
      return {
        isShow: false,
        index: 1,
        current: 0,
        CommodImgArr: [1,2,3,4],
        fsInfos: '',
        addressArr: [],
      }
    },
    methods: {
      goBack(){
        this.$router.push('/myMall');
      },
      onChange(index) {
        this.current = index;
      },
      reduceNub() {
        this.index--;
        if (this.index < 1) {
          document.body.style.overflow = '';//出现滚动条
          this.$toast('数量不能少于1');
          this.isShow = false;
          this.index = 1;
        }
      },
      augmentNub() {
        this.index++;
      },
      reselectPro() {
        this.isShow = false;
        document.body.style.overflow = '';//出现滚动条
      },
      addToCart() {
        document.body.style.overflow = 'hidden';
        this.isShow = true;
      },
      confirm() {
        this.$request.addCart({
          prodid: this.fsInfos._id,
          num: this.index,
        })
          .then((res) => {
            console.log(res);
            document.body.style.overflow = '';//出现滚动条
            if (res.data.code === 1) {
              this.isShow = false;
              this.$toast('购物车添加成功');
            }
          })
          .catch((error) => console.log(error));
      },
      shoppingTrolley() {
        this.$router.push('/shopping-trolley')
      },
    },
    created() {
      this.$request.getAddr()
        .then((res) => {
          // console.log(res);
          res.data.data.filter(value => {
            if (value.isDefault === true) {
              this.addressArr = value.location;
            }
          })

        })
        .catch((error) => console.log(error));

      if (this.$route.params.fsInfos) {
        this.fsInfos = this.$route.params.fsInfos;
        // console.log(this.fsInfos);
      }
    }
  };
</script>

<style lang="scss" scoped>
  @import "../../assets/font_1001665_wneao7ah2ln/iconfont.css";
  *{
    margin: 0;
    padding: 0;
  }
  a{
    color: #222222;
  }
  .commodity-header{
    background: white;
    width: 100vw;
    height: 80px;
    text-align: center;
    line-height: 80px;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 99999;
  }
  .returnUpper{
    position: absolute;
    top: 15px;
    left: 20px;
  }
  .commodity-item{
    font-size: 26px;
  }
  .commodity{
    display: inline-block;
    width: 100px;
    text-align: center;
  }
  .details{
    display: inline-block;
    width: 100px;
    text-align: center;
  }
  .share{
    position: absolute;
    top: 10px;
    right: 25px;
  }
  .share>img{
    width: 35px;
    height: 35px;
  }

  .commodity-property{
    overflow: auto;
    background: #f3f3f3;
  }
  .productsIn{
    width: 100vw;
    padding-top: 90px;
    overflow: hidden;
    position: relative;
  }
  .commodity-picture{
    width: 100vw;
    height: 50vh;
    background: white;
  }
  .pictureImg{
    width: 100vw;
    height: 50vh;
  }
  .custom-indicator{
    position: absolute;
    right: 40px;
    bottom: 20px;
    width: 70px;
    height: 40px;
    background: rgba(0,0,0,0.3);
    border-radius: 20px;
    color: white;
    line-height: 40px;
    text-align: center;
  }
  .commodity-introduce{
    width: 130vw;
    height: 100px;
    padding: 20px;
    background: #fff;
    overflow: hidden;
    margin-top: 20px;
    border-bottom: 1px solid #f1f1f1;
  }
  .commodity-title{
    font-size: 26px;
    width: 100vw;
    height: 32px;
    color: #363636;
    overflow: hidden;
  }
  .commodity-hint{
    font-size: 22px;
    color: #ff2e59;
    height: 40px;
    line-height: 40px;
  }
  .commodity-price{
    height: 40px;
    line-height: 40px;
    font-size: 26px;
    color: #676767;
  }
  .commodity-safeguard{
    height: 60px;
    line-height: 60px;
    background: #fff;
    width: 100vw;
    color: #6c6c6c;
    border-bottom: 1px solid #f1f1f1;
    position: relative;
  }
  .commodity-safeguard>img{
    width: 35px;
    position: absolute;
    top: 13px;
    left: 20px;
  }
  .safeguard-title{
    margin-left: 70px;
  }
  .shoppingAddress{
    width: 100vw;
    height: 90px;
    padding-left: 20px;
    padding-top: 20px;
    background: #fff;
    overflow: hidden;
    border-bottom: 1px solid #f1f1f1;
    position: relative;
  }
  .dispatch-location{
   margin-left: 20px;
  }
  .available{
    width: 80px;
    height: 35px;
    line-height: 35px;
    text-align: center;
    font-size: 24px;
    border: 1px solid #e09e67;
    border-radius: 10px;
    color: #e09e67;
    position: absolute;
    left: 130px;
    top: 60px;
  }
  .SelectNumber{
    height: 60px;
    line-height: 60px;
    background: #fff;
    width: 100vw;
    border-bottom: 1px solid #f1f1f1;
    padding-left: 20px;
    color: #9b9b9b;
    position: relative;
  }
  .commodity-number{
    margin-left: 50px;
  }
  .autonSelect{
    position: absolute;
    top: 10px;
    right: 40px;
    font-size: 40px;
    color: #838383;
  }
  .productDetails{
    width: 100vw;
    overflow: hidden;
    margin-top: 20px;
    margin-bottom: 80px;
  }
  .CommodTitle{
    height: 80px;
    line-height: 80px;
    width: 100vw;
    padding-left: 20px;
    position: relative;
    background: white;
  }
  .CommodTitle>div{
    width: 3px;
    height: 25px;
    background: #3e9bfe;
    position: absolute;
    left: 20px;
    top: 30px;
  }
  .CommodTitle>p{
    margin-left: 20px;
    font-size: 26px;
  }
  .imgDisplay li{
    width: 100vw;
    height: 550px;
    background: #fff;
  }
  .detailsPic{
    width: 100vw;
    height: 550px;
  }
  .trolleyCarMask{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 9999999;
  }
  .selectArea{
    width: 100vw;
    height: 70vh;
    position: fixed;
    bottom: 0;
    background: #fff;
    padding: 0 30px;
    z-index: 9999999999;
  }
  .merchandNews{
    width: 100vw;
    height: 200px;
    border-bottom: 1px solid #ddd;
    position: relative;
  }
  .pictureArea{
    width: 170px;
    height: 170px;
    border: 1px solid #f2f2f2;
    margin-top: -50px;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
  }
  .pictureArea>img{
    width: 169px;
    height: 169px;
  }
  .Locaedprice{
    position: absolute;
    top: 70px;
    left: 200px;
    font-size: 28px;
    color: #ff3000;
  }
  .productID{
    position: absolute;
    top: 120px;
    left: 200px;
    font-size: 24px;
    width: 600px;
    height: 26px;
    overflow: hidden;
  }
  .selectNub{
    position: relative;
  }
  .selectNub>span{
    position: absolute;
    top: 30px;
    left: 0;
    font-size: 28px;
  }
  .selectNubBtn{
    position: absolute;
    top: 20px;
    left: 80px;
    display: inline-block;
    border: 1px solid #bbb;
    border-radius: 10px;
    width: 180px;
    height: 50px;
  }
  .selectNubBtn>div{
    float: left;
    box-sizing: border-box;
    line-height: 50px;
    text-align: center;
  }
  .reduce{
    width: 30%;
    height: 50px;
    border-right: 1px solid #bbb;
  }
  .itesNumber{
    width: 40%;
    height: 50px;
  }
  .itesNumber>input{
    width: 60px;
    height: 40px;
    border: none;
    text-align: center;
  }
  .augment{
    width: 30%;
    height: 50px;
    border-left: 1px solid #bbb;
  }
  .affirmBtn{
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 80px;
    line-height: 80px;
    text-align: center;
    background: #3d9dfd;
    color: #fff;
  }
  .affirmBtn:active{
    background: #3d9dee;
  }
  .commodity-footer{
    height: 80px;
    width: 100vw;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    background: white;
  }
  .shoppingCart{
    position: absolute;
    top: 20px;
    left: 50px;
    font-size: 35px;
    color: #333;
  }
  .commodityBtn{
    position: absolute;
    top: 10px;
    right: 20px;
    width: 75%;
    border-radius: 50px;
    font-size: 0;
    overflow: hidden;
  }
  .commodityBtn>div{
    width: 50%;
    height: 60px;
    display: inline-block;
    font-size: 25px;
    color: white;
    line-height: 60px;
    text-align: center;
  }
  .addToCart{
    background: #f97b2e;
  }
  .immediatelyBuy{
    background: #3c9dfc;
  }
</style>
